﻿using System;
using System.Web.UI.WebControls;
using DBProvider;
using DBProvider.Providers;

namespace HealthCommunity.Controls
{
	public partial class UCMyExamination : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected void Page_PreRender(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				BindMyExamination();
			}
		}

		protected void gvExamination_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if(e.Row.DataItem != null)
			{
				var hlExamination = e.Row.FindControl("hlExamination") as HyperLink;
				var ltrExmtTotalScore = e.Row.FindControl("ltrExmtTotalScore") as Literal;
				var dataItem = e.Row.DataItem as RLT_UserAndExamination;

				hlExamination.Text = dataItem.Examination.ExaminationName;
				hlExamination.NavigateUrl = "~/ExaminationDetail.aspx?examinationid=" + dataItem.ExaminationID.ToString();

				ltrExmtTotalScore.Text = dataItem.Examination.ExaminationTotalScore.GetValueOrDefault(0).ToString();
			}
		}

		private void BindMyExamination()
		{
			var u = SiteContext.Current.CurrentUser;

			if(u != null)
			{
				var examinationProvider = new ExaminationProvider();

				gvExamination.DataSource = examinationProvider.GetUserAndExaminationByUser(u.UserID);
				gvExamination.DataBind();
			}
		}
	}
}